﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Shipwire.Messages;

namespace Shipwire.Tests
{
    /// <summary>
    /// Summary description for FulfillmentTests
    /// </summary>
    [TestClass]
    public class FulfillmentTests
    {
        [TestMethod]
        public void TestSingleOrder()
        {
            IShipwireService service = TestShipwireAccount.CreateSandboxService();

            FulfillmentOrder order = new FulfillmentOrder
            {
                Id = "TEST10",
                Email = "customer_email@customer_domain.com",
                CompanyName = "My Company",
                SameDay = SameDayRequest.NOT_REQUESTED,
                AddressInfo = new AddressInfo
                {
                    Name = new ShipwireName("Mr David Cameron"),
                    Address1 = "House of Commons",
                    Address2 = "",
                    City = "London",
                    State = "Greater London",
                    Zip = "SW1A 0PW",
                    Country = "UK",
                    Phone = "",
                    Commercial = false
                },
                Items = new OrderItem[] { new OrderItem { Code = TestShipwireAccount.TestProductCode, Quantity = 1, Num = "0" } }
            };

            var response = service.PlaceOrder(order);

            Assert.AreEqual("0", response.Status);
            Assert.IsNull(response.ErrorMessage);

            Assert.AreEqual(1, response.TotalItems);
            Assert.AreEqual(1, response.TotalOrders);

            Assert.IsNotNull(response.TransactionId);

            Assert.IsNotNull(response.Orders[0].Id);
            Assert.IsNotNull(response.Orders[0].Number);
            Assert.AreEqual("accepted", response.Orders[0].Status);
        }

        [TestMethod]
        public void TestMultipleOrders()
        {
            IShipwireService service = TestShipwireAccount.CreateSandboxService();

            FulfillmentOrder order = new FulfillmentOrder
            {
                Id = "TEST10",
                Email = "customer_email@customer_domain.com",
                CompanyName = "My Company",
                SameDay = SameDayRequest.NOT_REQUESTED,
                AddressInfo = new AddressInfo
                {
                    Name = new ShipwireName("Mr David Cameron"),
                    Address1 = "House of Commons",
                    Address2 = "",
                    City = "London",
                    State = "Greater London",
                    Zip = "SW1A 0PW",
                    Country = "UK",
                    Commercial = true,
                    Phone = "0161-GOV1",
                    Email = "sc@gov.uk"
                },
                Items = new OrderItem[] { new OrderItem { Code = TestShipwireAccount.TestProductCode2, Quantity = 1, Num = "0" } }
            };

            FulfillmentOrder order1 = new FulfillmentOrder
            {
                Id = "TEST11",
                Email = "customer_email2@customer_domain.com",
                CompanyName = "My Company 2",
                SameDay = SameDayRequest.NOT_REQUESTED,
                AddressInfo = new AddressInfo
                {
                    Name = new ShipwireName("Mr George Osborne"),
                    Address1 = "House of Commons 2",
                    Address2 = "",
                    City = "London",
                    State = "Greater London",
                    Zip = "SW1A 0PW",
                    Country = "UK",
                    Commercial = false,
                    Phone = "0161-GOV2",
                    Email = "pm@gov.uk"
                },
                Items = new OrderItem[] { new OrderItem { Code = TestShipwireAccount.TestProductCode2, Quantity = 1, Num = "0" } }
            };

            var response = service.PlaceOrder(order, order1);

            Assert.AreEqual("0", response.Status);
            Assert.IsNull(response.ErrorMessage);

            Assert.AreEqual(2, response.TotalItems);
            Assert.AreEqual(2, response.TotalOrders);

            Assert.IsNotNull(response.TransactionId);

            Assert.IsNotNull(response.Orders[0].Id);
            Assert.IsNotNull(response.Orders[0].Number);
            Assert.AreEqual("accepted", response.Orders[0].Status);

            Assert.IsNotNull(response.Orders[1].Id);
            Assert.IsNotNull(response.Orders[1].Number);
            Assert.AreEqual("accepted", response.Orders[1].Status);
        }
    }
}
